<?php
namespace app\common\repositories\info;
use app\common\repositories\BaseRepository;
use app\common\dao\info\UserIntegralDao as dao;
use app\common\repositories\user\UserRepository;

/**
 * @mixin dao
 */
class UserIntegralRepository extends BaseRepository
{
    public function __construct(dao $dao)
    {
        $this->dao = $dao;
    }


    public function addIntegral($uid,$count,$title)
    {
        if(!$count) return;

        $type = 1;

        $this->dao->create(compact('uid','count','title','type'));

        app()->make(UserRepository::class)->incrNumberField($uid,'integral',$count);
    }


    public function subIntegral($uid,$count,$title)
    {
        if(!$count) return;

        $type = 0;

        $this->dao->create(compact('uid','count','title','type'));

        app()->make(UserRepository::class)->incrNumberField($uid,'integral',$count*-1);
    }
}